﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData;
using BaseData.UI;
using TaxBiz.SysConfig;
using TaxBiz.House;
using TaxEntity.House;

namespace Admin.House
{
    public partial class ZiyongInput : BaseCommon.BasePage
    {
        protected string certificateID = string.Empty;
        protected HouseInfoEntity hie = null;
        protected string pName = string.Empty;
        protected string pIDCardNum = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.DoAction(action);
            }
            else
            {
                //初始化;
                certificateID = PageContext.GetRequest("certificateID", 50);
                if (!string.IsNullOrEmpty(certificateID))
                {
                    hie = new HouseInfoBiz().GetEntityByCertificateID(certificateID);
                    if (hie == null)
                    {
                        Jscript.AlertAndGoBack("参数错误，不能操作");
                        return;
                    }
                    else
                    {
                        pName = hie.Name;
                        pIDCardNum = hie.IDCardNum;
                    }
                }
            }
        }

        protected bool DoAction(string action)
        {
            RentInfoBiz rib = new RentInfoBiz();
            RentInfoEntity rie = new RentInfoEntity();
            rie.OptUserID = UserLogin.UserId;
            rie.HouseType2 = "自用";
            rie.CertificateID = PageContext.GetRequest("txtCertificateID", 50);
            if (String.IsNullOrEmpty(rie.CertificateID))
            {
                Jscript.AlertAndGoBack("房产证编号不能为空");
                return false;
            }
            rie.Name = PageContext.GetRequest("txtName", 20);
            rie.IDCardNum = PageContext.GetRequest("txtIDCardNum", 25);
            string strStartDate = PageContext.GetRequest("txtStartDate");
            if (!string.IsNullOrEmpty(strStartDate))
            {
                rie.StartDate = DateTime.Parse(strStartDate);
            }
            string strEntDate = PageContext.GetRequest("txtEndDate");
            if (!string.IsNullOrEmpty(strEntDate))
            {
                rie.EndDate = DateTime.Parse(strEntDate);
            }

            long id = rib.Add(rie, UserLogin);
            if (id <= 0)
            {
                Jscript.Alert("添加失败");
                return false;
            }

            Jscript.AlertAndRedirect("添加成功", "ZiyongInput.aspx");
            return true;
        }
    }
}